package com.smarth.zhizulian.utils;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * Created by KUMA on 2017/1/19.
 */
public class TimeUtils {
    public static String format(Date date) {
        if (date == null) {
            return "未知时间";
        }
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
//        SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss");
        return sdf.format(date);
    }

    public static String getLeftTime(long leftTime) {
        long day = leftTime / (1000 * 60 * 60 * 24);
        long hour = (leftTime / (1000 * 60 * 60) - day * 24);
        long min = ((leftTime / (60 * 1000)) - day * 24 * 60 - hour * 60);
        long s = (leftTime / 1000 - day * 24 * 60 * 60 - hour * 60 * 60 - min * 60);
        return ("<font color=\"#f1f321\">" + hour + "</font>小时<font color=\"#f1f321\">" + min + "</font>分<font color=\"#f1f321\">" + s + "</font>秒");
    }

    public static String getHongBaoLeftTime(long leftTime) {
        long day = leftTime / (1000 * 60 * 60 * 24);
        long hour = (leftTime / (1000 * 60 * 60) - day * 24);
        long min = ((leftTime / (60 * 1000)) - day * 24 * 60 - hour * 60);
        long s = (leftTime / 1000 - day * 24 * 60 * 60 - hour * 60 * 60 - min * 60);
        return (String.format("%02d", hour) +":" + String.format("%02d", min) + ":" + String.format("%02d", s));
    }

    public static String getHongBaoRainTime(long leftTime) {
        long day = leftTime / (1000 * 60 * 60 * 24);
        long hour = (leftTime / (1000 * 60 * 60) - day * 24);
        long min = ((leftTime / (60 * 1000)) - day * 24 * 60 - hour * 60);
        long s = (leftTime / 1000 - day * 24 * 60 * 60 - hour * 60 * 60 - min * 60);
        return s + "s";
    }

    public static String getFriendHongBaoTime(long leftTime) {
        long day = leftTime / (1000 * 60 * 60 * 24);
        long hour = (leftTime / (1000 * 60 * 60) - day * 24);
        long min = ((leftTime / (60 * 1000)) - day * 24 * 60 - hour * 60);
        long s = (leftTime / 1000 - day * 24 * 60 * 60 - hour * 60 * 60 - min * 60);
        return (String.format("%02d", min) +":" + String.format("%02d", s));
    }

    public static String getActivityLeftTime(long leftTime) {
        long day = leftTime / (1000 * 60 * 60 * 24);
        long hour = (leftTime / (1000 * 60 * 60) - day * 24);
        long min = ((leftTime / (60 * 1000)) - day * 24 * 60 - hour * 60);
        long s = (leftTime / 1000 - day * 24 * 60 * 60 - hour * 60 * 60 - min * 60);
        return ("活动倒计时:<font color=\"#fdfe4f\">" + day + "</font>天<font color=\"#fdfe4f\">" + hour + "</font>小时<font color=\"#fdfe4f\">" + min + "</font>分钟");
    }
}
